<script>
	function changeLabelProductToCode()
	{
		var check = document.getElementById("searchWithCodeChck").checked;
		if(check == true)
		{
			document.getElementById("searchWithProduct").innerHTML = "Find by code";
			document.getElementById("exampleInputEmail1").placeholder = "Enter code";
			document.getElementById("exampleInputEmail1").setAttribute("name","code")
		}
		else
		{
			document.getElementById("searchWithProduct").innerHTML = "Find by product";
			document.getElementById("exampleInputEmail1").placeholder = "Enter product";
			document.getElementById("exampleInputEmail1").setAttribute("name","product")
		}
	}
	function changeLabelCodeToProduct()
	{
		var check = document.getElementById("searchWithProductChck").checked;
		if(check == false)
		{
			document.getElementById("searchWithProduct").innerHTML = "Find by code";
			document.getElementById("exampleInputEmail1").placeholder = "Enter code";
			document.getElementById("exampleInputEmail1").setAttribute("name","code")
		}
		else
		{
			document.getElementById("searchWithProduct").innerHTML = "Find by product";
			document.getElementById("exampleInputEmail1").placeholder = "Enter product";
			document.getElementById("exampleInputEmail1").setAttribute("name","product")
		}
	}	
	function showForm(product_id)
	{		
		if(document.getElementById('storage_form'+product_id).style.display == 'none')
		{
			document.getElementById('storage_form'+product_id).style.display = 'block';
		}
		else
		{
			document.getElementById('storage_form'+product_id).style.display = 'none'
		}
	}	
</script>
<?php 
	if(isset($searchByCode) && !empty($searchByCode)):
?>
<form role="form" method="post" action="<?=site_url('code/search') ?>">
  <div class="form-group">
    <label for="exampleInputEmail1" id="searchWithProduct">Find by code</label>
    <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Enter code" name="code" value="<?=(!empty($input_search)) ? $input_search : '' ?>">
  </div>  
  <div class="checkbox">
    <label>
      <input type="checkbox" id="searchWithProductChck" onClick="changeLabelCodeToProduct()">* Find by product
    </label>
  </div>
  <button type="submit" name="searchBtn" class="btn btn-primary">Search</button>
</form>
<?php
	else:
?>
<form role="form" method="post" action="<?=site_url('code/search') ?>">
  <div class="form-group">
    <label for="exampleInputEmail1" id="searchWithProduct">Find by product</label>
    <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Enter product" name="product" value="<?=(!empty($input_search)) ? $input_search : '' ?>">
  </div>  
  <div class="checkbox">
    <label>
      <input type="checkbox" id="searchWithCodeChck" onClick="changeLabelProductToCode()">* Find by code
    </label>
  </div>
  <button type="submit" name="searchBtn" class="btn btn-primary">Search</button>
</form>
<?php
	endif;
?>

<div class="table-responsive">
	<table class="table">
		<thead>
			<tr align="center">										
				<td>Title</td>
				<td>Storage</td>
				<td>Color</td>			
				<td>XS</td>
				<td>S</td>
				<td>M</td>
				<td>L</td>
				<td>XL</td>
				<td>XXL</td>
				<td>XXXL</td>	
				<td>Action</td>			
			</tr>
		</thead>
		<tbody>			
			<?php										
				foreach($products as $product):

				$product_id = $product['id'];
			?>
			<form role="form" method="post" action="<?=site_url('code/edit/'.$product_id) ?>">
			<tr align="center">	
				<td>
					<?=$product['title'] ?>													
				</td>
				<td>
					<button type="submit" name="addStorageBtn" value="<?=$product_id?>" class="btn btn-success">Add Storage</button>					
				</td>								
				<td><?=(empty($product['color'])) ? '' : $product['color'] ?></td>
				<td><?=(empty($product['xs'])) ? '' : $product['xs'] ?></td>				
				<td><?=(empty($product['s'])) ? '' : $product['s'] ?></td>
				<td><?=(empty($product['m'])) ? '' : $product['m'] ?></td>
				<td><?=(empty($product['l'])) ? '' : $product['l'] ?></td>
				<td><?=(empty($product['xl'])) ? '' : $product['xl'] ?></td>
				<td><?=(empty($product['xxl'])) ? '' : $product['xxl'] ?></td>
				<td><?=(empty($product['xxxl'])) ? '' : $product['xxxl'] ?></td>
				<td>
					<button type="submit" name="editCode" value="<?=$product['id'] ?>" class="btn btn-primary">Edit</button><br/>										
				</td>				
			</tr>				
			</form>
			<?php							
				endforeach;				
			?>
		</tbody>
	</table>
</div>
